﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace The.NET_Downloader
{
    /// <summary>
    /// Interaction logic for NewDownloadWindow.xaml
    /// </summary>
    public partial class NewDownloadWindow : Window
    {
        public Uri DownloadUri { get; private set; }
        public NewDownloadWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                DownloadUri = new Uri(textBox2.Text);                
            }
            catch
            {
                return;
            }
            this.DialogResult = true;
            
            this.Close();
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
            this.Close();
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            string t = Clipboard.GetText();
            try
            {
                Uri u = new Uri(t);
            }
            catch
            {
                textBox2.Focus();
                textBox2.Select(textBox2.Text.Length, 0);
                return;


            }
            button1.Focus();
            textBox2.Text = t;
        }

        private void textBox2_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Return)
                button1_Click(sender, e);
        }
    }
}
